<template >
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="手机号" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="咨询人员" prop="consultant">
        <el-input
          v-model="queryParams.consultant"
          placeholder="请输入咨询人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="归属校区" prop="belongingToCampus">
        <el-input
          v-model="queryParams.belongingToCampus"
          placeholder="请输入归属校区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来源" prop="source">
        <el-input
          v-model="queryParams.source"
          placeholder="请输入来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业大学" prop="graduationFromUniversity">
        <el-input
          v-model="queryParams.graduationFromUniversity"
          placeholder="请输入毕业大学"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="跟踪次数" prop="trackingTimes">
        <el-input
          v-model="queryParams.trackingTimes"
          placeholder="请输入跟踪次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <table  class="centered-table" style="border-collapse: collapse; border: 1px solid black;">
      <thead>
      <tr>
        <th  class="centered-table" style="border: 1px solid black;">统计维度</th>
        <th  class="centered-table" style="border: 1px solid black;">潜在录入数</th>
      </tr>
      </thead>
      <tbody>
      <tr v-for="(item, index) in somedata" :key="index"  class="centered-table" style="border: 1px solid black;">
        <td  class="centered-table" style="border: 1px solid black;">{{ item.inputTime }}</td>
        <td  class="centered-table" style="border: 1px solid black;">{{ item.id }}</td>
      </tr>
      </tbody>
    </table>
  <div id="line-chart" style="width: 100%; height: 400px;">

  </div>

  </div>
</template>

<script>
import { listReport, getReport, delReport, addReport, updateReport } from "@/api/custom/report";
import * as echarts from 'echarts';
export default {
  name: "Report",
  data() {
    return {
      somedata:[],

      datasj:[],
      datasm:[],
      option:{},
      chartDom:null,
      myChart:null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 潜在学员报表表格数据
      reportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        age: null,
        wechat: null,
        qq: null,
        phoneNumber: null,
        gender: null,
        intendedSubject: null,
        interestLevel: null,
        inputterTeacher: null,
        consultant: null,
        inputTime: null,
        lastFollowUpTime: null,
        intendedClass: null,
        source: null,
        education: null,
        graduationFromUniversity: null,
        graduationTime: null,
        reference: null,
        seniorStudents: null,
        speciality: null,
        yearsOfService: null,
        currentState: null,
        nextFollowUptime: null,
        trackingTimes: null,
        belongingToCampus: null,
        trackRecord: null,
        untracedTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        inputTime: [
          { required: true, message: "录入时间不能为空", trigger: "blur" }
        ],
        lastFollowUpTime: [
          { required: true, message: "最后跟踪时间不能为空", trigger: "blur" }
        ],
      }
    };
  },
  mounted() {
    this.getList();
  },
  created() {
  },
  methods: {

    eChartsLine(){
      console.log(this.chartDom,"-----")
      // 获取图表容器
      this.chartDom = document.getElementById('line-chart');
      // 初始化ECharts实例
      this.myChart = echarts.init(this.chartDom);
      // 配置图表数据及选项
      this.option = {
        xAxis: {
          type: 'category', // 横轴一般为类别轴（如果是时间序列，则为'time'类型）
          // 横轴标签
          data:this.datasm
        },
        yAxis: {
          type: 'value', // 纵轴一般为数值轴
        },
        series: [{
          data: this.datasj, // 折线图的数据序列
          type: 'line', // 图表类型为折线图
          smooth: true, // 可选，是否平滑曲线显示
        }],
        title: {
          text: '一周销售统计'
        },
        tooltip: {} // 可选，提示框组件配置
      };

    // 将配置项给ECharts实例对象
      this.myChart.setOption(this.option);
    },


    /** 查询潜在学员报表列表 */
    getList() {
      this.loading = true;
      listReport(this.queryParams).then(response => {

        this.reportList = response.rows;
        this.datasm=response.rows.map(item=>item.inputTime);
        this.datasj=response.rows.map(item=>item.id);
        this.somedata=response.rows;
        console.log(this.datasm);
        this.eChartsLine();
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        age: null,
        wechat: null,
        qq: null,
        phoneNumber: null,
        gender: null,
        intendedSubject: null,
        interestLevel: null,
        inputterTeacher: null,
        consultant: null,
        inputTime: null,
        lastFollowUpTime: null,
        intendedClass: null,
        source: null,
        education: null,
        graduationFromUniversity: null,
        graduationTime: null,
        reference: null,
        seniorStudents: null,
        speciality: null,
        yearsOfService: null,
        currentState: null,
        nextFollowUptime: null,
        trackingTimes: null,
        belongingToCampus: null,
        trackRecord: null,
        untracedTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加潜在学员报表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getReport(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改潜在学员报表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateReport(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReport(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除潜在学员报表编号为"' + ids + '"的数据项？').then(function() {
        return delReport(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('custom/report/export', {
        ...this.queryParams
      }, `report_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.centered-table {
  text-align: center;
}

.centered-cell {
  text-align: center;
}
</style>
